package edu.thu.studio.ormdesigner.editor.command;

import edu.thu.studio.ormdesigner.common.AbstractCommand;
import edu.thu.studio.ormdesigner.model.diagram.Diagram;
import edu.thu.studio.ormdesigner.model.diagram.node.ViewNode;

public class CreateViewNodeShortCutCommand extends AbstractCommand {
    
    private Diagram diagram;
    
    private ViewNode node;
    
    public CreateViewNodeShortCutCommand(Diagram diagram, ViewNode node) {
        this.diagram = diagram;
        node.setDiagram(diagram);
        node.checkAndInit();
        this.node = node;
    }
    
    /**
     * {@inheritDoc}
     */
    @Override
    protected void doExecute() {
        this.diagram.getNodes().addObject(node);
        this.diagram.refreshChildren();
    }
    
    /**
     * {@inheritDoc}
     */
    @Override
    protected void doUndo() {
        this.diagram.getNodes().remove(node);
        this.diagram.refreshChildren();
    }
    
}
